package com.wm.blog_gateway.auth;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/***
 * @ClassName: PasswordEncoderImpl
 * @Description: 自定义的密码加密方法，实现了PasswordEncoder接口  spring security
 * @Author: wm_yu
 * @Create_time: 16:50 2020-3-30
 */
@Service
public class PasswordEncoderImpl implements PasswordEncoder {

    @Override
    public String encode(CharSequence charSequence) {
        if(StringUtils.isEmpty(charSequence)){
            charSequence = "";
        }
        //自定义加密方式 todo
        return charSequence.toString() ;
    }

    /**
     * 校验密码,用户传入的密码和查询数据库的密码
     * @param charSequence  传入的密码
     * @param s  查询数据库后保存在内存中的密码
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return encode(charSequence).equals(s);
    }
}
